
<template>
  <ex_super_dialog_form ref="reportDialog" v-bind="report_dialog" v-on="$listeners" @afterSubmitSuccess="submit">
  </ex_super_dialog_form>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      report_dialog: {
        customClass: "dialog_auto",
        submitDataHandle: (data) => {
          const { attachedList, ...other } = data;
          if (attachedList) {
            if (this.isMainSystem || this.isWmsSystem) {
              other.anomalyAttachedList = attachedList;
            } else if (this.isTmsSystem) {
              other.attachedDTOList = attachedList;
            }
          }
          return other;
        },

        form: {
          itemClass: "form_item_default",
          inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            {
              label: "label_order_count",
              render: (h, { data }) => h('span', {},data.orderNum)
            },
            {
              label: "label_receipt_waybill_count",
              render: (h, { data }) => h('span', {},data.tmsOrderNum)
            },
            {
              label: "label_customer_name",
              render: (h, { data }) => h('span', {}, data.customerName)
            },
            {
              label: "label_total_box_count",
              render: (h, { data }) => h('span', {}, data.totalBoxCount)
            },
            {
              label: "label_total_sku_count",
              render: (h, { data }) => h('span', {}, data.totalQuantity)
            },
            {
              key: "tmsReceiptHandoverEnum",
              label: "label_receipt_handover_type",
              type: "select",
              attrs: {
                enum: "TmsReceiptHandoverEnum",
              },
            },
            {
              if:(data)=>data.tmsReceiptHandoverEnum=== 'FACE_TO_FACE',
              key: "handoverUsername",
              label: "label_handover_person",
            },
            {
              if:(data)=>data.tmsReceiptHandoverEnum=== 'EXPRESS',
              key: "handoverExpressNo",
              label: "label_tms_ems_no",
            },

            {
              key: "handoverNum",
              label: "label_receipt_recycle_num",
              attrs: {type:"number", maxlength: 9, "show-word-limit": true },
            },
          ],
          rules: {
            tmsReceiptHandoverEnum: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
            handoverUsername: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
            handoverNum: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
            handoverExpressNo: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
          },
        },
      },

    }
  },

  methods: {
    show(rows) {
      this.receiptIdList = []
      const obj = {
        customerName:'',
        carrierNameList:[],
        totalBoxCount:0,
        totalQuantity:0,
        // 后面两个字段无意义，产品要求先显示
        orderNum:rows.length,
        tmsOrderNum:rows.length
      }
      rows.forEach(item=>{
        this.receiptIdList.push(item.id)
        obj.customerName = item.customerName
        obj.carrierNameList.push(...item.carrierNameList)
        obj.totalBoxCount+=item.totalBoxCount
        obj.totalQuantity+=item.totalQuantity
      })
      obj.carrierNameList = obj.carrierNameList.join(',')
      const option = Object.assign(
        {
          title: this.$t("label_tms_receipt_receipt_handover"),
          // submitUrl: this.$url["tms/BaseAnomalyReport"],
          // detailUrl:this.$url["wms/BaseAnomalyDetail"],
        },
        {
          data: obj,
          onlySetData: true,
          submitCall:(data,formData,submitCallResult)=>{
            submitCallResult(true,true,false)
          },
        }
      );
      console.log(option)
      this["$refs"]["reportDialog"].showNew(option);
    },
    submit(data) {
      this.$ajax({
        url: "/tms-api/task/TmsOrderReceiptInfoRpc/handoverReceiptInfo.json",
        method: 'post',
        type: 'json',
        data:{
            "receiptIdList":this.receiptIdList,//数组
            "tmsReceiptHandoverEnum":data.tmsReceiptHandoverEnum,//回收方式
            "handoverNum":data.handoverNum,//回收数量
            "handoverUsername":data.handoverUsername,//回收人
            "handoverExpressNo":data.handoverExpressNo//回收邮寄单号
        },
        success: (res) => {
          this.$message.success(this.$t("label_receipt_tip_submit_recycle"))
          this.$emit('submitSuccess')
        }
      })

    }
  }
}
</script>
